#include "xrouter_server.h"
#include "xrouter_handle.h"
#include <config/config_client/XConfigClient.h>
#include <XSSL/XSSLCtx.h>
XRouterServer::XRouterServer()
{
}

void XRouterServer::Main(int argc, char *argv[])
{
}

XServiceHandle *XRouterServer::CreateServiceHandle()
{
    bool is_ok=true;
    bool is_ssl = XConfigClient::Get()->GetBool("is_ssl",&is_ok);
    if(!is_ssl||!is_ok){
        return new XRouterHandle();
    }
    XRouterHandle *handle=new XRouterHandle();
    // 已经设置，暂时不修改
    if(sslCtx()){
        return handle;
    }
    auto *ctx=new XSSLCtx();
    auto crt_path = XConfigClient::Get()->GetString("crt_path");
    auto key_path = XConfigClient::Get()->GetString("key_path");
    auto ca_path = XConfigClient::Get()->GetString("ca_path");
    ctx->InitServer(crt_path.c_str(),key_path.c_str(),ca_path.c_str());
    setSSLCtx(ctx);
    return handle;
}